import hyRequest from "../..";
import { getCurrentToken } from "../login";
const token = getCurrentToken();

/**
 * @获取列表
 * @param query
 * @returns
 */
export const getArticleList = (query: {
  pageNum: number;
  pageSize: number;
}) => {
  return hyRequest.get({
    url: "/article/list",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    params: query,
  });
};
/**
 * @修改文章
 * @param body
 * @returns
 */
export const modifyArticleInfo = (body: {
  comments: number;
  content: string | null;
  createBy: string | null;
  createTime: string | null;
  id: number | null;
  image: string | null;
  likes: number | null;
  remark: string | null;
  state: string;
  sysDeptId: number | null;
  title: string;
  updateBy: string | null;
  updateTime: string | null;
  userId: number;
}) => {
  return hyRequest.put({
    url: "/article",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
};
/**
 * @通过id获取文章详细
 * @param id
 * @returns
 */
export function getArticleDetailById(id: number) {
  return hyRequest.get({
    url: `/article/${id}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}
/**
 * @新增
 * @param body
 * @returns
 */
export function addArticleInfo(body: {
  content: string | null;
  createBy: string | null;
  createTime: null;
  id: null | number;
  image: null | string;
  likes: null | number;
  state: string;
  sysDeptId: number | null;
  sysUserId: null;
  title: string;
  updateBy: null | string;
  updateTime: null | string;
}) {
  return hyRequest.post({
    url: "/article/uploads",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
}

/**
 * @批量删除
 * @param ids
 * @returns
 */
export function deleteArticleById(ids: string[]) {
  const idsStr = ids.join(",");
  return hyRequest.delete({
    url: `article/${idsStr}`,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
}
